/*
 * @(#)UserManage.java Time: 2013-3-8
 *
 * Copyright 2013 xuedou.com All rights reserved.
 */

package xuedou.skymoni.util;

import java.io.File;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

/**
 *<pre>类说明</pre>
 *<b>功能描述：</b>
 * 从本地远程导入数据.
 * @author  meiguanghui meiguanghui@xuedou.com
 * @version 1.0, 2013-3-8
 */
public class ImportStudents {
	
	
	public static void  insertDate(String xlsPath) {
        try   {
           File excelFile = new  File(xlsPath);
           
           if(excelFile.exists()) {
        	   
               Workbook book  =  Workbook.getWorkbook(excelFile);
               //获得第一个工作表对象
               Sheet sheet  =  book.getSheet( 0 );
               
               Cell cell1 = null;
               String vluaes = "";
               
               //获取总行数
               int rows = sheet.getRows();
               for(int i = 1; i< rows;i++) {
               	for(int j = 0; j<2 ; j++) {
               	 //列行
                 	  cell1  =  sheet.getCell(j,i);
                 	  if(j != 1){
                     	  vluaes +=  "'" + cell1.getContents().trim() + "'" + ",";  
                 	  } else {
                     	  vluaes +=  "'" + cell1.getContents().trim() + "'";
                 	  }
               	}
               	
                  String sqlStr = "insert into skystudent(stunumber,stuname) values("+vluaes+")";
                  
                  JDBCUtil jdbcUtil = JDBCUtil.getJDBCUtil();
                  
                  jdbcUtil.update(sqlStr, new String[]{});
                  
                  jdbcUtil.free();
                 
                  
                  vluaes = "";
               
               }
              book.close();
              //删除文件,放置重复导入
              System.out.println("\n导入数据库完毕");
              System.out.println("删除xcel标记: "+excelFile.delete());
           } else {
        	   System.out.println("文件不存在了!");
           }
          
       }   catch  (Exception e)  {
           System.out.println(e);
       }
	}
}
